home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8967 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Why is Gets() so bad?
  5. Date: Thu, 07 Mar 96 17:55:30 GMT
  6. Organization: none
  7. Message-ID: <826221330snz@genesis.demon.co.uk>
  8. References: <4hb1ie$pa7@ixnews2.ix.netcom.com> <4hdvuv$3vr@gryphon.phoenix.net> <4hl7cp$m84@ns2.ptd.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4hl7cp$m84@ns2.ptd.net> onyx@postoffice.ptd.net "Matt Ayres" writes:
  15.  
  16. >I am still sorta a newbie and I hate gets() for that reason. Could you 
  17. >show me some code to write my own gets() function? It would be much 
  18. >help.
  19.  
  20. The normal approach is to use fgets() instead which allows you to specify the
  21. length of the buffer you are passing it. Unlike gets() fgets() writes the
  22. line terminating '\n' character at the end of the string. If this causes
  23. problems you'll have to get rid of it yourself. You can however use it to
  24. test whether you read a full line i.e. your buffer was large enough. It can
  25. be the basis of an algorithm to read an arbitrarily long line if you wish.
  26.  
  27. -- 
  28. -----------------------------------------
  29. Lawrence Kirby | fred@genesis.demon.co.uk
  30. Wilts, England | 70734.126@compuserve.com
  31. -----------------------------------------
  32.